package cn.itzd.controller;

import cn.itzd.entity.TbDemo;
import cn.itzd.utils.PageUtils;
import cn.itzd.utils.result.R;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: dada
 * @Version: 1.0
 * @Description: 测 试 类
 */
@RestController
@RequestMapping("/demo")
public class DemoController extends BaseController{
    @GetMapping("/list")
    public R<?> list(TbDemo item) {
        PageUtils.start();
        List<TbDemo> list = demoService.lambdaQuery()
                .like(!ObjectUtils.isEmpty(item.getName()),TbDemo::getName,item.getName().trim())
                .list();
        return R.table(list);
    }

    @PostMapping
    public R<?> add(@RequestBody TbDemo item) {
        return R.ok(demoService.save(item));
    }

    @PutMapping
    public R<?> edit(@RequestBody TbDemo item) {
        return R.ok(demoService.updateById(item));
    }

    @DeleteMapping("/{id}")
    public R<?> delete(@PathVariable("id") Long id) {
        return R.ok(demoService.removeById(id));
    }

    @GetMapping("getById/{id}")
    public R<?> getById(@PathVariable String id) {
        return R.ok(demoService.getById(id));
    }


}
